package com.rfs.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.alibaba.fastjson.JSON;
import com.dtflys.forest.annotation.Request;
import com.rfs.client.ForestClientTest;
import com.rfs.config.MQConfiguration;
import com.rfs.dto.HumpInputDto;
import com.rfs.dto.TestValidDto;
import com.rfs.mq.OrderStateChangeMQDto;
import com.rfs.mq.RMQProducer;
import com.rfs.utils.XLoggerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private RMQProducer rmqProducer;
    @Autowired
    private MQConfiguration mqConfiguration;
    @Autowired
    private ForestClientTest forestClientTest;

    @GetMapping("/index")
    public String index() {
        XLoggerUtil.info("测试日志");
        return "123";
    }

    @GetMapping("/sendmq")
    public OrderStateChangeMQDto sendMq(String tag) {
        OrderStateChangeMQDto orderStateChangeMQDto = OrderStateChangeMQDto.builder()
                .orderId(RandomUtil.randomLong(0, 100000))
                .sysCode(18)
                .state(1)
                .userId(1L)
                .createTime(DateUtil.date())
                .build();

        rmqProducer.sentMessage(orderStateChangeMQDto, mqConfiguration.getOrderStateChangeTopic(), String.valueOf(orderStateChangeMQDto.getOrderId()), tag);
        return orderStateChangeMQDto;
    }

    @PostMapping("/testValid")
    public String testValid(@RequestBody @Valid TestValidDto dto) {
        return "ok-state-" + dto.getState();
    }

    @GetMapping("/helloForest")
    public String helloForest() {
        return forestClientTest.helloForest();
    }

    @RequestMapping(value = "/hump")
    public String hump(HumpInputDto dto) {
        return "bb"+JSON.toJSONString(dto);
    }


}
